import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import ConfigElementType 1.0
import "qrc:/qmlComponents/ConfigManager"
import "qrc:/qmlComponents/AxisModulePos"
import "qrc:/qmlComponents/CustomizedUIElement"

Item {
    RowLayout{
        spacing: 50

        GroupBox{
            title: qsTr("SensorTrayInputElevator")

            Layout.alignment: Qt.AlignTop

            ColumnLayout{
                ConfigRow{
                    configModel: steConfig
                    configName: "stieMagTrayCount"
                    Component.onCompleted: {
                        autoInit()
                    }
                }

                SAxisModulePos{
                    moduleName: "STIE"
                    posName: "KickFirtTrayPos"
                }
                SAxisModulePos{
                    moduleName: "STIE"
                    posName: "KickLastTrayPos"
                }

                GroupBox{
                    ColumnLayout{
                        RowLayout{
                            RadioButton{
                                id: rdbStieMag1
                                checked: true
                                text: qsTr("Mag1")
                            }
                            RadioButton{
                                text: qsTr("Mag2")
                            }
                            Label{
                                text: qsTr("TrayIndex")
                            }
                            TextField{
                                id: txtStieTrayIndex
                                text: "1"
                                validator: IntValidator{}
                                implicitWidth: 50
                                selectByMouse: true
                            }
                        }
                        RowLayout{
                            Button{
                                text: qsTr("MoveToMagTrayPos")
                                onClicked: {
                                    tem.runSingleCmd(stie, "moveToMagTrayPos", [rdbStieMag1.checked ? 1 : 2, txtStieTrayIndex.text])
                                }
                            }
                            Button{
                                text: qsTr("ResetMagTrayState")
                                onClicked: {
                                    tem.runSingleCmd(stie, "resetMagTrayState", [rdbStieMag1.checked ? 1 : 2])
                                }
                            }
                        }
                    }
                }

                RowLayout{
                    Button{
                        text: qsTr("KickTray")
                        onClicked: {
                            tem.runSingleCmd(stie, "kickTray")
                        }
                    }
                    Button{
                        text: qsTr("RetractKicker")
                        onClicked: {
                            tem.runSingleCmd(stie, "retractKicker")
                        }
                    }
                }
            }
        }

        GroupBox{
            title: qsTr("SensorTrayOutputElevator")

            Layout.alignment: Qt.AlignTop

            ColumnLayout{
                ConfigRow{
                    configModel: steConfig
                    configName: "stoeMagTrayCount"
                    Component.onCompleted: {
                        autoInit()
                    }
                }

                SAxisModulePos{
                    moduleName: "STOE"
                    posName: "RetrieveFirstTrayPos"
                }
                SAxisModulePos{
                    moduleName: "STOE"
                    posName: "RetrieveLastTrayPos"
                }

                GroupBox{
                    ColumnLayout{
                        RowLayout{
                            RadioButton{
                                id: rdbStoeMag1
                                checked: true
                                text: qsTr("Mag1")
                            }
                            RadioButton{
                                text: qsTr("Mag2")
                            }
                            Label{
                                text: qsTr("TrayIndex")
                            }
                            TextField{
                                id: txtStoeTrayIndex
                                text: "1"
                                validator: IntValidator{}
                                implicitWidth: 50
                                selectByMouse: true
                            }
                        }
                        RowLayout{
                            Button{
                                text: qsTr("MoveToMagTrayPos")
                                onClicked: {
                                    tem.runSingleCmd(stoe, "moveToMagTrayPos", [rdbStoeMag1.checked ? 1 : 2, txtStoeTrayIndex.text])
                                }
                            }
                            Button{
                                text: qsTr("ResetMagTrayState")
                                onClicked: {
                                    tem.runSingleCmd(stoe, "resetMagTrayState", [rdbStoeMag1.checked ? 1 : 2])
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
